0

IpInterfaceUC UserControl

<div id="dvChannel" runat="server">
        <asp:GridView ID="gvChannelUC" 
            OnRowCommand="gvChannelUC_RowCommand"
            OnSelectedIndexChanged="gvChannel_SelectedIndexChanged"
        />
</div>

IPServices page CodeBehind

if (!IsPostBack){
}else
{    
 string str_btn = Request.Form.Keys[Request.Form.Keys.Count - 1].ToString();
 handleClick(str_btn);
}

Question

It always show str_btn is null.If I click Button,It'll show button's id.But when I click Select at GridView,It show str_btn is null.It should be show GridView's id when we click select.

Thanks for any explain.

Brian
  • 163
  • 2
  • 18

2 Answers2

0

Try giving name attribute to your gridview,ie name="yourGridName".

<div id="dvChannel" runat="server" name="yourGridName">
        <asp:GridView ID="gvChannelUC" name="yourGridName"
            OnRowCommand="gvChannelUC_RowCommand"
            OnSelectedIndexChanged="gvChannel_SelectedIndexChanged"
        />
</div>
sajanyamaha
  • 3,119
  • 2
  • 26
  • 44
0

As per my understanding you need grid event handing (.ascx) on page/codebehind (.aspx).

declare eventhandler in userControl

 public event EventHandler<EventArgs>  RaiseSelectedIndexChanged=delegate {};

handle userControl selectedindexchanged event in userControl.cs

   protected void gvChannel_SelectedIndexChanged(object sender, EventArgs e)
    {
        var raiseSelectedIndexChanged = RaiseSelectedIndexChanged ;
        if(raiseSelectedIndexChanged!=null)
        {
            raiseSelectedIndexChanged(sender, e);
        }
    }

register and use your userControl in aspx (which I hope you already did) this code will go in aspx page

        <uc:userControl OnRaiseSelectedIndexChanged="OnRaiseSelectedIndexChanged"/>

handle the event in aspx code behind

    protected void OnRaiseSelectedIndexChanged(object sender, EventArgs e)
    {
       //handle your event and put logic 
    }

I hope i make it clear , let me know if it confuses you.

Paritosh
  • 2,303
  • 2
  • 18
  • 24
  • Thanks for your reply.;).I have some question.Hoping you'll help me figure out of it.Thanks.**var raiseSelectedIndexChanged = RaiseSelectedIndexChanged **.Because It was used at codebehind.May you rewrite this code.I think it will not work at codebehind.;) – Brian Jan 07 '13 at 05:25
  • I did not get you , please tell me what is not working or post your sample code so that I can modify it. – Paritosh Jan 07 '13 at 05:29
  • var raiseSelectedIndexChanged = RaiseSelectedIndexChanged; It didnt' work – Brian Jan 07 '13 at 07:08
  • is it giving compilation error ? I am using .net 4.0 , so var is allowed. try this EventHandler raiseSelectedIndexChanged = RaiseSelectedIndexChanged ; – Paritosh Jan 07 '13 at 07:36
  • It work fine.But I used event at dynamic control.So that,I can't use . http://stackoverflow.com/questions/14150848/get-gridview-in-multiple-usercontrol-from-codebehind/14150889#comment19599867_14150889. Do you have any solution.Thanks – Brian Jan 07 '13 at 07:53
  • ctrIpInterfaceUC.RaiseSelectedIndexChanged += new EventHandler(OnRaiseSelectedIndexChanged); – Brian Jan 08 '13 at 08:19
  • My Scenario is that have 2 usercontrol.So that,At individual usercontrol,I register OnRaiseSelectedIndexChanged function for it.But it didn't run this function (I debug by VS2008) – Brian Jan 08 '13 at 08:21
  • Do you have any solution,brother.I can share teamviewer's id for your help.Thanks – Brian Jan 08 '13 at 08:22
  • please send you code at paritoshmmmec@gmail.com, I will see what i can do to help you to accomplish your task , I will be availble after 10 PM – Paritosh Jan 08 '13 at 08:25
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22369/discussion-between-binh-tieu-and-paritosh) – Brian Jan 08 '13 at 09:39